﻿#include "RegexFunctions.h"

Regex *RegexFunctions::ChatItemLinks = new Regex(R"(<(.*?/.*?)>)");

std::string RegexFunctions::RegexReplace(const std::string &text, Regex *regex, MatchEvaluator ev)
{
    try
    {
        return regex->Replace(text, ev);
    }
    catch (...)
    {
        return text;
    }
}

std::string RegexFunctions::SeperateCamelCase(const std::string &value)
{
    return StringHelper::trim(Regex::Replace(value, "((?<=[a-z])[A-Z]|[A-Z](?=[a-z]))", " $1"));
}

MatchEvaluator RegexFunctions::GetMatchEv(RegexMatchEvalType type)
{
    switch (type)
    {
        case RegexMatchEvalType::ChatLinkName:
            return [&] (std::any m)
            {
                m::Groups[1].Captures[0]->Value->Split('/')[0];
            };
        default:
            return nullptr;
    }
}

std::string RegexFunctions::CleanChatString(const std::string &text)
{
    return RegexReplace(text, ChatItemLinks, [&] (System::Text::RegularExpressions::Match match) {return GetMatchEv(match);});
}
